package com.gitee.huanminabc.utils_tools.spring_base.config;

import com.gitee.huanminabc.jcommon.multithreading.executor.ThreadFactoryUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @program: java-huanmin-utils
 * @description: 配置线程池
 * @author: huanmin
 * @create: 2024-12-11 12:17
 **/
@Configuration
@ConfigurationProperties(prefix = "thread-config")
@Data
@Slf4j
public class ThreadFactoryConfig {
    private Map<String, ThreadConfig> pool;
    @Data
    public static class   ThreadConfig{
        private int maxPoolSize;//最大线程数
        private int queue;//任务数
    }

    @PostConstruct
    public void init(){
        if (pool==null){
            log.warn("线程池配置为空");
            return;
        }
        pool.forEach((k,v)->{
            ThreadFactoryUtil.addExecutor(k,v.getMaxPoolSize(),v.getQueue());
            log.info("线程池{}初始化成功",k);
        });
    }
}
